/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.misc;


import java.util.Collection;


/**
 * String utilities.
 */
final public class Strings {

	
	/**
	 * Static utility class, do not instantiate.
	 */
	private Strings() {
	}
	

	/**
	 * Returns the collection as a string.
	 * 
	 * @param list    the collection to stringify
	 * @param start   prepended to the resulting string
	 * @param end     appended to the resulting string
	 * @param delim   the delimiter to use between list elements
	 * @return  the string
	 */
	public static String list(Collection list, String start, String end, String delim) {
		StringBuffer result = new StringBuffer();
		result.append(start);
		boolean comma = false;
		for (Object o: list) {
			if (comma) {
				result.append(delim);
			} else {
				comma = true;
			}
			result.append(o);
		}
		result.append(end);
		return result.toString();
	}
	
	
	/**
	 * Returns the collection as a string surrounded by parentheses with elements
	 * separated by commas.
	 * 
	 * @param list  the collection to stringify
	 * @return  the string
	 */
	public static String list(Collection list) {
		return list(list, "(", ")", ", ");
	}
}
